﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageWeighedLateness : Objective
    {
        public AverageWeighedLateness()
            : base()
        {
        }
        public AverageWeighedLateness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageWeighedLateness = 0;
            double totalWeighedLateness = 0;

            int lateness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                lateness = order.EndDate - order.DueDate;
                totalWeighedLateness = totalWeighedLateness + (order.Weight * lateness);
            }

            averageWeighedLateness = totalWeighedLateness / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageWeighedLateness,2);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderWeightValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
            validators.Add(new OrderDueDateValidator(SchEduData));
        }


        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Weighed Lateness";
                aboutInfo.Guid = new Guid("{D72DA4BA-E66D-473d-97D3-4C3C48FB93F6}");
                aboutInfo.Description = Resources.AverageWeightedLatenessDescription;
                return aboutInfo;
            }
        }

    }
}
